import Shape from '../core/core.shape';
import { Core } from '../core/core';

interface ICircle extends Partial<Core.IAttr> {
  x: number,
  y: number,
  r: number,
}

export default class Circle extends Shape {
  attrs: ICircle = {
    x: null,
    y: null,
    r: null,
    lineWidth: 1
  }
  constructor(attrs: ICircle) {
    super('circle', {});
    this.attrs = { ...super.attr(),...this.attrs, ...attrs };
  }
  createPath() {
    const { x, y, r, ...attrs } = this.attrs;
    const context = this.getProps('context');
    context.beginPath();
    context.arc(x, y, r, 0, Math.PI * 2, false);
    console.log('create-circle-path');
  }
  attr<T extends Partial<ICircle>, U extends keyof ICircle>(param?: T | U, value?: T[U]) {
    // 无参数 返回当前类所有属性
    if (!param) {
      return this.attrs;
    }

    // 只有一个参数属性名 返回该属性值
    if (typeof param === 'string' && !value) {
      return this.attrs[param];
    }

    // 设置属性值
    if (typeof param === 'string') {
      this.attrs[param] = value;
      return;
    }

    // 设置属性值
    if (typeof param === "object") {
      this.attrs = Object.assign(this.attrs, param);
      return;
    }
  }
}